Return to start page
Core/Interface/Library Misc.j
1 library ALibraryCoreInterfaceMisc initializer init requires ALibraryCoreStringConversion
2
3 globals
4 // keys
5 constant integer AKeyEscape = 0
6 constant integer AKeyUp = 1
7 constant integer AKeyDown = 2
8 constant integer AKeyRight = 3
9 constant integer AKeyLeft = 4
10 // shortcuts for dialogs (ASCII values)
11 constant integer AShortcutBackspace = 8
12 constant integer AShortcutTab = 9
13 constant integer AShortcutEscape = 27
14 constant integer AShortcutSpace = 32
15 constant integer AShortcut0 = 48
16 constant integer AShortcut1 = 49
17 constant integer AShortcut2 = 50
18 constant integer AShortcut3 = 51
19 constant integer AShortcut4 = 52
20 constant integer AShortcut5 = 53
21 constant integer AShortcut6 = 54
22 constant integer AShortcut7 = 55
23 constant integer AShortcut8 = 56
24 constant integer AShortcut9 = 57
25 // small letters
26 constant integer AShortcutA = 65
27 constant integer AShortcutB = 66
28 constant integer AShortcutC = 67
29 constant integer AShortcutD = 68
30 constant integer AShortcutE = 69
31 constant integer AShortcutF = 70
32 constant integer AShortcutG = 71
33 constant integer AShortcutH = 72
34 constant integer AShortcutI = 73
35 constant integer AShortcutJ = 74
36 constant integer AShortcutK = 75
37 constant integer AShortcutL = 76
38 constant integer AShortcutM = 77
39 constant integer AShortcutN = 78
40 constant integer AShortcutO = 79
41 constant integer AShortcutP = 80
42 constant integer AShortcutQ = 81
43 constant integer AShortcutR = 82
44 constant integer AShortcutS = 83
45 constant integer AShortcutT = 84
46 constant integer AShortcutU = 85
47 constant integer AShortcutV = 86
48 constant integer AShortcutW = 87
49 constant integer AShortcutX = 88
50 constant integer AShortcutY = 89
51 constant integer AShortcutZ = 90
52 //dialogs
53 constant integer AMaxDialogButtons = 12 /// @todo 16?
54 endglobals
55
56 debug function KeyIsValid takes integer key returns boolean
57 debug return key >= AKeyEscape and key <= AKeyLeft
58 debug endfunction
59
60 function TriggerRegisterKeyEventForPlayer takes player user, trigger usedTrigger, integer key, boolean press returns event
61 debug if (not KeyIsValid(key)) then
62 debug call Print("TriggerRegisterKeyEventForPlayer: Invalid key " + I2S(key) + ".")
63 debug endif
64 if (key == AKeyEscape) then
65 debug if (not press) then
66 debug call Print("TriggerRegisterKeyEventForPlayer: Escape key release event can't be used.")
67 debug endif
68 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_END_CINEMATIC)
69 elseif (key == AKeyUp) then
70 if (press) then
71 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_UP_DOWN)
72 else
73 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_UP_UP)
74 endif
75 elseif (key == AKeyDown) then
76 if (press) then
77 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_DOWN_DOWN)
78 else
79 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_DOWN_UP)
80 endif
81 elseif (key == AKeyRight) then
82 if (press) then
83 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_RIGHT_DOWN)
84 else
85 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_RIGHT_UP)
86 endif
87 elseif (key == AKeyLeft) then
88 if (press) then
89 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_LEFT_DOWN)
90 else
91 return TriggerRegisterPlayerEvent(usedTrigger, user, EVENT_PLAYER_ARROW_LEFT_UP)
92 endif
93 endif
94 return null
95 endfunction
96
97 function GetModifiedPlayerName takes player whichPlayer returns string
98 local playercolor playerColor = GetPlayerColor(whichPlayer)
99 local string modifiedPlayerName = "|c00" + PlayerColorToString(playerColor) + GetPlayerName(whichPlayer) + "|r |c00ffffff[" + I2S(GetPlayerId(whichPlayer) + 1) + "]|r"
100 set playerColor = null
101 return modifiedPlayerName
102 endfunction
103
104 function GetBar takes real value, real maxValue, integer length, string colour returns string
105 local integer i
106 local integer colouredPart
107 local string result = ""
108 debug if (maxValue == 0.0) then
109 debug call Print("GetBar: Invalid maxValue parameter with value " + R2S(maxValue) + ".")
110 debug return null
111 debug endif
112 set colouredPart = R2I(value * I2R(length) / maxValue)
113 //coloured part exists
114 if (colouredPart > 0.0) then
115 set result = "|c00" + colour
116 endif
117 set i = 0
118 loop
119 exitwhen(i == length)
120 set result = result + "|"
121 //set end of coloured part
122 if ((i == colouredPart) and (colouredPart > 0.0) and (colouredPart != length)) then
123 set result = result + " |c00ffffff"
124 endif
125 set i = i + 1
126 endloop
127 return result
128 endfunction
129
130 /// @todo test please
131 function SetUnitVertexColourForPlayer takes player whichPlayer, unit whichUnit, real red, real green, real blue, real transparency returns nothing
132 local player localPlayer = GetLocalPlayer()
133 if (whichPlayer == localPlayer) then
134 call SetUnitVertexColorBJ(whichUnit, red, green, blue, transparency)
135 endif
136 set localPlayer = null
137 endfunction
138
139 globals
140 private sound error
141 endglobals
142
143 /// @author Vexorian
144 /// @source http://www.wc3c.net/showthread.php?t=101260
145 function SimError takes player whichPlayer, string message returns nothing
146 local player localPlayer = GetLocalPlayer()
147 set message = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00" + message + "|r"
148 if (localPlayer == whichPlayer) then
149 call ClearTextMessages()
150 call DisplayTimedTextToPlayer(whichPlayer, 0.52, 0.96, 2.00, message)
151 call StartSound(error)
152 endif
153 set localPlayer = null
154 endfunction
155
156 private function init takes nothing returns nothing
157 set error = CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
158 //call StartSound( error ) //apparently the bug in which you play a sound for the first time
159 //and it doesn't work is not there anymore in patch 1.22
160 endfunction
161
162 endlibrary